package me.zhengjie.modules.quartz.task.count;

import com.alibaba.fastjson.JSONObject;
import com.qiaofang.applet.common.constant.SyncTypeEnum;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.quartz.service.dto.SyncCommon;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: youqing.yang
 * @Create: 2020/11/10 10:52
 * @Description:
 **/
@Slf4j
@Component
public class AllSyncCountTask extends CountTaskBase{

    @Autowired
    AllSynchronizeDataCount allSynchronizeDataCount;

    @Override
    protected void count(SyncCommon syncCommon) {

        try {
            for (SyncTypeEnum item : SyncTypeEnum.values()) {
                if (StringUtils.equals(item.getSyncType(), SyncTypeEnum.CITY.getSyncType())) {
                    continue;
                }
                log.info("run companyUuid {} SyncType {} start ", syncCommon.getCompanyUuid(), item.getSyncType());
                Long startTime = System.currentTimeMillis();
                allSynchronizeDataCount.pull(syncCommon, item.getSyncType());
                Long endTime = System.currentTimeMillis();
                log.info("run companyUuid {} SyncType {} end costTime:{}ms ", syncCommon.getCompanyUuid(), item.getSyncType(), (endTime - startTime));
            }
        } catch (Exception e) {
            log.error(" error params:{} error: {}", JSONObject.toJSONString(syncCommon), e);
        }
    }


}
